﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BO;

namespace GUI
{
    public partial class Form1 : Form
    {
        HashSet<DTO_DiaDiem> listDD = new HashSet<DTO_DiaDiem>();
        string query = "select * from DiaDiem";
        public void GUI_loadDiaDiem()
        {
            BO_DiaDiem dd = new BO_DiaDiem();
            listDD = dd.BO_loadDiaDiem(query);
            DataTable dt = new DataTable();
            dt.Columns.Add("MaDD", typeof(String));
            dt.Columns.Add("TenDD", typeof(String));
            dt.Columns.Add("MaNoi", typeof(String));
            foreach (DTO_DiaDiem i in listDD)
            {              
                DataRow dr = dt.NewRow();
                dr["MaDD"] = i.Madd;            
                dr["TenDD"] = i.Tendd;               
                dr["MaNoi"] = i.Manoi;
                dt.Rows.Add(dr);
            }
            dataGridView1.DataSource = dt;
        }
        public Form1()
        {

            InitializeComponent();
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
            GUI_loadDiaDiem();
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            query = "select * from DiaDiem";
            GUI_loadDiaDiem();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                string key = textBox1.Text.ToString();
                query = "select * from DiaDiem where MaDD ='" + key + "'";
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                string key = textBox1.Text.ToString();
                query = "select * from DiaDiem where TenDD ='" + key + "'";
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                string key = textBox1.Text.ToString();
                query = "select * from DiaDiem where MaNoi ='" + key + "'";
            }
            GUI_loadDiaDiem();
        }
    }
}
